package auth

import groovy.transform.CompileStatic

class User4Platform implements Comparable<User4Platform> {

    Platform platform
    String code //wechat->unionId
    String phoneNumber
    String invoiceTitle

    Date dateCreated
    Date lastUpdated

    @CompileStatic
    static enum Platform {
        App(1), Alipay(8), Wechat(9)

        final int id;

        Platform(int id) {
            this.id = id
        }
    }

    static belongsTo = [user4Core: User4Core]
    static hasMany = [clients: User4Client]

    static constraints = {
        platform(nullable: false)
        code(nullable: false)
        phoneNumber(nullable: null)
        invoiceTitle(nullable: null)
        user4Core(nullable: true)
    }

    static mapping = {
        platform enumType: 'identity'
    }

    @Override
    int compareTo(User4Platform o) {
        dateCreated <=> o.dateCreated
    }
}
